package com.glory.brepda.adapter;

import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.widget.CheckBox;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * FileName: AddCarrierDataAdapter
 * Author: XJH
 * Date: 2020/5/22 19:52
 * Description:
 * History:
 */
public class CarrierCheckAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private SparseArray<Boolean> checkList;

    public CarrierCheckAdapter(@Nullable List<String> data) {
        super(R.layout.item_add_carrier_data,data);
        checkList = new SparseArray();

    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        helper.setText(R.id.tvPosition,String.valueOf(helper.getAdapterPosition() + 1))
                .setText(R.id.tvCarrierID,String.valueOf(item))
                .setGone(R.id.ivDelete,false)
                .setGone(R.id.llCbLayout,true);

        CheckBox checkBox = helper.getView(R.id.checkbox);
        if (checkList.get(helper.getAdapterPosition()) == null){
            checkBox.setChecked(false);
            checkList.put(helper.getAdapterPosition(),false);
        }else {
            checkBox.setChecked(checkList.get(helper.getAdapterPosition()));
        }
    }

    public SparseArray<Boolean> getCheckList(){
        return checkList;
    }

    public void setCheck(String s){
        int index = getData().indexOf(s);
        checkList.put(index,true);
        notifyItemChanged(index);
    }

}
